Tuesday, January 26, 2010

SiteHelp.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Spaces;
using System.IO;

///
/// SiteHelp 的摘要说明
///

public class SiteHelp
{
public SiteHelp()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 图片路径的处理
public static string GetImgUrl(Photo p)
{
string imgName = string.Format("{0}{1}",p.PhotoID, Path.GetExtension(p.SmallPic));
string cacheImg = GetImageCacheFullPath(p.Account, imgName);
if (File.Exists(cacheImg))
{
return GetImageCacheUrl(p.Account, imgName);
}
return string.Format("{0}/photo.ashx?u={1}&p={2}", Globals.ApplicationPath, p.Account, Des.Encrypt(p.PhotoID + "", "xiaoxiao"));
}
public static string GetImageCacheUrl(string account, string pid)
{
return string.Format("{0}/{1}/{2}", WapConfig.Get().ImageCacheUrl, account, pid);
}
public static string GetImageCacheFullPath(string account, string pid)
{
return string.Format("{0}\\{1}\\{2}", WapConfig.Get().ImageCachePath, account, pid);
}
public static string GetMainImg(PhotoCategory c)
{
string img = "";
if (c.MainPhotoID < 1) return img;
string imgName = string.Format("{0}{1}", c.MainPhotoID, Path.GetExtension(c.Image));
string cacheImg = GetImageCacheFullPath(c.Account, imgName);
if (File.Exists(cacheImg))
{
return GetImageCacheUrl(c.Account, imgName);
}
return string.Format("{0}/photo.ashx?u={1}&p={2}", Globals.ApplicationPath, c.Account, Des.Encrypt(c.MainPhotoID.ToString(), "xiaoxiao"));
}
#endregion
public const string NavAFormat = "{0}
";
const string nextPageFormat="[3]下一页";
const string prvPageFormat="[1]上一页";
public static string MakePager(string baseUrl,int curPage, int pageSize, int count)
{
StringBuilder sb = new StringBuilder();
string c = "?";
if (baseUrl.IndexOf("?") != -1)
c = "&";
if (curPage <= 1 )
{
if(pageSize >= count)
return string.Empty;

sb.AppendFormat(nextPageFormat,baseUrl+c+"page=2");
return sb.ToString();
}
sb.AppendFormat(prvPageFormat, baseUrl+c+"page=" + (curPage - 1));

if (count > (curPage * pageSize))
{
sb.Append(" ");
sb.AppendFormat(nextPageFormat, baseUrl+c+"page=" + (curPage + 1));
}
int pageCount=0;
if((count%pageSize)>0)
{
pageCount=(count/pageSize)+1;
}else
pageCount=(count/pageSize);

sb.AppendFormat("({0}/{1})",curPage,pageCount);
return sb.ToString();
}
public static string BottomNav()
{
StringBuilder sb = new StringBuilder();

sb.Append("[*] 页首
");
sb.Append("[#] 页尾
");
sb.AppendFormat("[0] I-Favourite首页
", HttpContext.Current.Response.ApplyAppPathModifier(Globals.GetWapSiteUrls().HomePage()));
return sb.ToString();
}


}

MobileForm.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.MobileControls;
///
/// MobileForm 的摘要说明
///

public class MobileForm:Form
{
public MobileForm()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}

FormFixerHtml32TextWriter.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.UI.MobileControls.Adapters;
using System.Web.Mobile;

#region FormFixerHtml32TextWriter
public class FormFixerHtml32TextWriter : System.Web.UI.HtmlTextWriter
{
private string _url; // 假的URL

public FormFixerHtml32TextWriter(TextWriter writer)
: base(writer)
{
_url = HttpContext.Current.Request.RawUrl;
}

public override void WriteAttribute(string name, string value, bool encode)
{
// 如果当前输出的属性为form标记的action属性,则将其值替换为重写后的虚假URL
if (_url != null && string.Compare(name, "action", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}
}
#endregion

#region FormFixerHtmlTextWriter
public class FormFixerHtmlTextWriter : HtmlMobileTextWriter

{
private string _url;
public FormFixerHtmlTextWriter(TextWriter writer,MobileCapabilities device)
: base(writer,device)
{
_url = HttpContext.Current.Request.RawUrl;

}




public override void WriteAttribute(string name, string value, bool encode)
{

if ( string.Compare(name, "action", true) == 0)
{
value = _url;
}

base.WriteAttribute(name, value, encode);
}
}
#endregion

Dicts.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Spaces;
using System.Text.RegularExpressions;

///
/// Dicts 的摘要说明
///

public class Dicts
{
public Dicts()
{

}
public static bool IsCN(string strIn)
{
return Regex.IsMatch(strIn, "[\u4E00 - \u9FA0]+ ");
}


const string CacheEntityKey="dict_entity_hashtable";
public static string KeyToValue(string key)
{
CacheEntity dict = new CacheEntity(CacheEntityKey);
return dict[key];
}
public static void AddValue(string key, string value)
{
CacheEntity dict = new CacheEntity(CacheEntityKey);
dict.Add(key, value);

}
///
/// 获取格言
///

///
///
public static string GetMaxim(string Source)
{
string str = Utils.SqlInput(Source);
string key = string.Format("en_Maxim_{0}",str);
string outValue = KeyToValue(key);
if (!string.IsNullOrEmpty(outValue))
return outValue;

string strSQL = "SELECT top 1 detaile FROM [en_maxim] WHERE (detaile LIKE '%" + str + "%')";

try
{
outValue = SpacesDataProvider.Instance().ExecuteScalar(strSQL).ToString();
AddValue(key, outValue);
return outValue;
}
catch
{
return "";
}
}
public static DataView GetEnWord(string Source)
{
string str = Utils.SqlInput(Source);

string key=string.Format("en_enword_{0}",str);
DataView dv=IFCache.Get(key) as DataView;
if (dv == null)
{
string strSQL = "select top 3 * from en_dictEC where source='" +str + "'";
dv = SpacesDataProvider.Instance().GetDataView(strSQL);
IFCache.Insert(key, dv, 6000);
}
return dv;
}

public static DataView GetCnWord(string Source)
{

string str = Utils.SqlInput(Source);

string key = string.Format("en_cnword_{0}", str);
DataView dv = IFCache.Get(key) as DataView;
if (dv == null)
{
string strSQL = "select top 3 * from en_dictCE where source='" + str + "'";
dv = SpacesDataProvider.Instance().GetDataView(strSQL);
IFCache.Insert(key, dv, 6000);
}
return dv;
}





public static DataRow GetSentsCE(string Scan, string Source)
{
string str = Utils.SqlInput(Source);

string key = string.Format("en_SentsCE_{0}", str);

DataRow dr = IFCache.Get(key) as DataRow;
if (dr == null)
{
string strSQL = "SELECT top 1 * FROM en_SentsCE WHERE (" + Scan + " LIKE '%" + str + "%')";
dr = SpacesDataProvider.Instance().GetDataRow(strSQL);
if (dr == null)
dr = new DataTable().NewRow();
IFCache.Max(key, dr);
}
return dr;
}



public static string GetSentence(string Source)
{
string str = Utils.SqlInput(Source);
string key = string.Format("en_n1000_{0}", str);
string outValue = KeyToValue(key);
if (!string.IsNullOrEmpty(outValue))
return outValue;

string strSQL = "SELECT top 1 detaile FROM en_n1000 WHERE (detaile LIKE '%" + str + "%')";

try
{
outValue = SpacesDataProvider.Instance().ExecuteScalar(strSQL).ToString();
AddValue(key, outValue);
return outValue;
}
catch
{
return "";
}
}






}

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PhotoPatchUpload
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}